//
//  CZTabbarController.m
//  CZOC微博01
//
//  Created by 1 on 15/11/23.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "CZTabbarController.h"
#import "CZDiscoverTableViewController.h"
#import "CZHomeTableViewcontroller.h"
#import "CZMesssageTableViewController.h"
#import "CZProfileTableViewController.h"
#import "CZNavigaitonViewController.h"
#import  "CZTabbar.h"

@interface CZTabbarController ()<CZTabBarDelegate>

@end

@implementation CZTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CZHomeTableViewcontroller *home=[[CZHomeTableViewcontroller alloc]init];
    [self addChildController:home title:@"首页" normalImage:@"tabbar_home" SelectedName:@"tabbar_home_highlighted"];
    
    CZMesssageTableViewController *message=[[CZMesssageTableViewController alloc]init];
    [self addChildController:message title:@"消息" normalImage:@"tabbar_message_center" SelectedName:@"tabbar_message_center_highlighted"];
    
    CZDiscoverTableViewController *discover=[[CZDiscoverTableViewController alloc]init];
    [self addChildController:discover title:@"发现" normalImage:@"tabbar_discover" SelectedName:@"tabbar_discover_highlighted"];
    
    CZProfileTableViewController *profile=[[CZProfileTableViewController alloc]init];
    [self addChildController:profile title:@"我" normalImage:@"tabbar_profile" SelectedName:@"tabbar_profile_highlighted"];
    
//    [self  setValue:[[CZTabbar alloc] init] forKey:@"tabbar"];
    CZTabbar *tab=[[CZTabbar alloc] init];
       tab.delegate=self;
    [self setValue:tab forKeyPath:@"tabBar"];
    
 
    
 

}
//实现它的代理方法
 - (void)tabBarClickPushButton:(CZTabbar *)tabBar
{
    UIViewController *vC=[[UIViewController alloc]init];
    vC.view.backgroundColor=[UIColor grayColor];
    [self presentViewController:vC animated:YES completion:nil];
}
- (void)addChildController:(UIViewController *)controller title:(NSString *)title normalImage:(NSString *)normalImage SelectedName:(NSString *)selectedImage
{
    
//    controller.view.backgroundColor=CZRandomColor;
//    controller.tabBarItem.title=title;
//    controller.navigationItem.title=title;
    controller.title=title;
    controller.tabBarItem.image=[UIImage imageNamed:normalImage];
    //    v1.tabBarItem.selectedImage=[UIImage imageNamed:@"tabbar_home_highlighted"];
    //声明这张图片的按照原来的样子显示出来 ，不要自动渲染他的颜色
    UIImage *img=[UIImage imageNamed:selectedImage];
    controller.tabBarItem.selectedImage=[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateHighlighted];
    
    CZNavigaitonViewController *nav=[[CZNavigaitonViewController alloc]initWithRootViewController:controller];
    
    [self addChildViewController:nav];
    
    
    
}

@end
